﻿@functions {
    private bool UserInCrudRoles(string controller)
    {
        return (User.IsInRole("Admin")
            || User.IsInRole(controller + " Read Public")
            || User.IsInRole(controller + " Read Private"));
    }
    private bool UserInRoles(string roles)
    {
        if (User.IsInRole("Admin"))
        {
            return true;
        }
        
        foreach (String role in roles.Split(',').Select(x => x.Trim()))
        {
            if(User.IsInRole(role))
            {
                return true;
            }
        }

        return false;
    }
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - Quản trị Chợ Mỹ</title>
    @Styles.Render("~/Content/admin-css")
    @RenderSection("styles", required: false)
    @Scripts.Render("~/bundles/modernizr")

</head>
<body class="skin-blue">
    <header class="header">
        <a href="#" class="logo">
            Chợ Mỹ
        </a>
        <nav class="navbar navbar-static-top" role="navigation">
            <a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-right">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="#">
                            <i class="fa fa-envelope"></i>
                            <span class="label label-success">4</span>
                        </a>
                    </li>
                    <li>
                        <a href="@Url.Action(null, "Order")">
                            <i class="fa fa-shopping-cart"></i>
                            <span class="label label-warning">4</span>
                        </a>
                    </li>
                    @*@Html.Action("Single", "User", new { partialView = "_NavbarTop" })*@
                </ul>
            </div>
        </nav>
    </header>
    <div class="wrapper row-offcanvas row-offcanvas-left">
        <aside class="left-side sidebar-offcanvas">
            <section class="sidebar">
                @*@Html.Action("Single", "User", new { partialView = "_SidebarLeft" })*@
                <form action="#" method="get" class="sidebar-form">
                    <div class="input-group">
                        <input type="text" name="q" class="form-control" placeholder="Tìm kiếm..." />
                        <span class="input-group-btn">
                            <button type='submit' name='seach' id='search-btn' class="btn btn-flat">
                                <i class="fa fa-search"></i>
                            </button>
                        </span>
                    </div>
                </form>
                <ul class="sidebar-menu">
                    <li id="home">
                        <a href="@Url.Action("Index", "Admin")">
                            <i class="fa fa-home"></i> <span>Trang chủ</span>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-cube"></i> <span>Sản phẩm</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("Product"))
                            {
                                <li id="manager-product">
                                    <a href="@Url.Action("Index", "Product")">
                                        <i class="fa fa-angle-double-right"></i> Danh sách
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("Brand"))
                            {
                                <li id="manager-brand">
                                    <a href="@Url.Action("Index", "Brand")">
                                        <i class="fa fa-angle-double-right"></i> Thương hiệu
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("Category"))
                            {
                                <li id="manager-category">
                                    <a href="@Url.Action("Index", "Category")">
                                        <i class="fa fa-angle-double-right"></i> Danh mục
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("PropertyType"))
                            {
                                <li id="manager-propertyType">
                                    <a href="@Url.Action("Index", "PropertyType")">
                                        <i class="fa fa-angle-double-right"></i> Loại thuộc tính
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("Property"))
                            {
                                <li id="manager-property">
                                    <a href="@Url.Action("Index", "Property")">
                                        <i class="fa fa-angle-double-right"></i> Thuộc tính
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-trophy"></i> <span>Sự kiện</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("Event"))
                            {
                                <li id="manager-event">
                                    <a href="@Url.Action("Index", "Event")">
                                        <i class="fa fa-angle-double-right"></i> Danh sách
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-road"></i> <span>Style</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("Trend"))
                            {
                                <li id="manager-trend">
                                    <a href="@Url.Action("Index", "Trend")">
                                        <i class="fa fa-angle-double-right"></i> Xu hướng
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-file-text"></i> <span>Bài đăng</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("Post"))
                            {
                                <li id="manager-post">
                                    <a href="@Url.Action("Index", "Post")">
                                        <i class="fa fa-angle-double-right"></i> Danh sách
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("PostGroup"))
                            {
                                <li id="manager-postGroup">
                                    <a href="@Url.Action("Index", "PostGroup")">
                                        <i class="fa fa-angle-double-right"></i> Nhóm
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-user"></i> <span>Người dùng</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("User"))
                            {
                                <li id="manager-user">
                                    <a href="@Url.Action("Index", "User")">
                                        <i class="fa fa-angle-double-right"></i> Danh sách
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("RoleGroup"))
                            {
                                <li id="manager-rolegroup">
                                    <a href="@Url.Action("Index", "RoleGroup")">
                                        <i class="fa fa-angle-double-right"></i> Nhóm phân quyền
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-group"></i> <span>Blog</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("BlogCategory"))
                            {
                                <li id="manager-blogcategory">
                                    <a href="@Url.Action("Index", "BlogCategory")">
                                        <i class="fa fa-angle-double-right"></i> Danh mục
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("BlogPost"))
                            {
                                <li id="manager-blogpost">
                                    <a href="@Url.Action("Index", "BlogPost")">
                                        <i class="fa fa-angle-double-right"></i> Bài đăng
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("BlogComment"))
                            {
                                <li id="manager-blogcomment">
                                    <a href="@Url.Action("Index", "BlogComment")">
                                        <i class="fa fa-angle-double-right"></i> Bình luận
                                    </a>
                                </li>
                            }                            
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-graduation-cap"></i> <span>Chuyên gia</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("MasterCategory"))
                            {
                                <li id="manager-mastercategory">
                                    <a href="@Url.Action("Index", "MasterCategory")">
                                        <i class="fa fa-angle-double-right"></i> Danh mục
                                    </a>
                                </li>
                            }                           
                            @if (UserInCrudRoles("MasterPost"))
                            {
                                <li id="manager-masterpost">
                                    <a href="@Url.Action("Index", "MasterPost")">
                                        <i class="fa fa-angle-double-right"></i> Bài đăng
                                    </a>
                                </li>
                            }  
                            @if (UserInCrudRoles("MasterComment"))
                            {
                                <li id="manager-mastercomment">
                                    <a href="@Url.Action("Index", "MasterComment")">
                                        <i class="fa fa-angle-double-right"></i> Bình luận
                                    </a>
                                </li>
                            }                              
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-gear"></i> <span>Tùy chọn khác</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInRoles("Exchange Rates"))
                            {
                                <li id="manager-exchangerates">
                                    <a href="#">
                                        <i class="fa fa-angle-double-right"></i> Tỷ giá ngoại tệ
                                    </a>
                                </li>
                            }
                            @if (UserInCrudRoles("Upload File"))
                            {
                                <li id="manager-uploadfile">
                                    <a href="#">
                                        <i class="fa fa-angle-double-right"></i> Tải lên
                                    </a>
                                </li>
                            }                            
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-bar-chart"></i> <span>Thống kê</span>
                            <i class="fa pull-right fa-angle-left"></i>
                        </a>
                        <ul class="treeview-menu">
                            @if (UserInCrudRoles("Statistics Input"))
                            {
                                <li id="manager-statistics-input">
                                    <a href="@Url.Action("Input", "Statistics")">
                                        <i class="fa fa-angle-double-right"></i> Nhập liệu
                                    </a>
                                </li>
                            } 
                        </ul>
                    </li>
                </ul>
            </section>
        </aside>
        <aside class="right-side">
            @RenderBody()
        </aside>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/admin-js")
    @RenderSection("scripts", required: false)
</body>
</html>